﻿using System.Configuration;
using System.IO;
using MbUnit.Framework;
using MockingBird.Simulator.Framework.Configuration;
using Moq;

namespace MockingBird.Simulator.FunctionalTests.EngineTests
{

    using MockingBird.Common.Infrastructure.Logging;
    using MockingBird.Simulator.FunctionalTests.Common;


    [TestFixture]
    public class HandlerConfigurationBehaviorFixture
    {

        private string testDataRoot = ConfigurationManager.AppSettings["TestData_Root"];
        private HandlerConfiguration configuration;

        /// <summary>
        /// This test checks if the manager is able to correctly return a known existing operation
        /// </summary>
        [Test]
        public void ShouldReturnOperationIfMatchExists()
        {
            var mockLogger = new Mock<ILogger>();
            var manager = new HandlerConfigurationManager(mockLogger.Object, TestHelper.GetAppConfigData());
            manager.InitializeConfigurationData(GetValidConfigFile());
            OperationType opType = manager.Find("GetCustomer");
            Assert.IsNotNull(opType);
            Assert.IsTrue(opType.ResponseStrategy == ResponseStrategyType.None);
        }

        /// <summary>
        /// This test verifies that the manager returns null if the required operation could not be found
        /// </summary>
        [Test]
        public void ShouldReturnNullIfNoOperationMatchExists()
        {
            var mockLogger = new Mock<ILogger>();
            var manager = new HandlerConfigurationManager(mockLogger.Object, TestHelper.GetAppConfigData());
            //load up a valid configuration into the manager
            manager.InitializeConfigurationData(GetValidConfigFile());
            OperationType opType = manager.Find("GetCustomerData");
            Assert.IsNull(opType);
        }



        #region "private helper methods"
        private string GetInvalidSchemaFile()
        {
            string invalidSchemaFile = ConfigurationManager.AppSettings["TestData_InvalidSchemaFileName"];
            invalidSchemaFile = Path.Combine(testDataRoot, invalidSchemaFile);
            return invalidSchemaFile;
        }

        private string GetValidConfigFile()
        {
            string invalidSchemaFile = ConfigurationManager.AppSettings["TestData_ValidConfigFileName"];
            invalidSchemaFile = Path.Combine(testDataRoot, invalidSchemaFile);
            return invalidSchemaFile;
        }

        #endregion


    }
}
